#include <iostream>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <unistd.h>

using namespace std;
mutex m;
condition_variable cond;
bool flag = false;

void fun()
{
    unique_lock<mutex> ul(m);
    cout << "已加锁，即将等待" << endl;
    while(flag != true)
    {
        cond.wait(ul);
        cout << "结束等待，判断flag条件" << endl;
    }
    cout << "执行任务。。。" << endl;
}

int main()
{
    thread th(fun);
    sleep(1);
    cond.notify_one();

    sleep(1);
    flag = true;
    cond.notify_one();
    
    th.join();
    cout << "end" << endl;
    return 0;
}